#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of KeyExtracta
# <http://code.google.com/p/keyextracta/>.
#
# KeyExtracta is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# KeyExtracta is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with KeyExtracta.  If not, see <http://www.gnu.org/licenses/>.

from PyQt4.QtGui import QKeySequence, QShortcut, QDialog, QDesktopServices
from PyQt4.QtCore import SIGNAL, SLOT, QUrl, QCoreApplication
from src.ui.ui_aboutDialog import Ui_aboutDialog

class AboutDialog(QDialog, Ui_aboutDialog):
  """"""
  def __init__(self, parent):
    super(QDialog, self).__init__(parent)
    self.setupUi(self)
    
    self.connect(self.pushButton_ok, SIGNAL("clicked()"),
      SLOT("accept()"))

    self.connect(QShortcut(QKeySequence("Ctrl+W"),self),
      SIGNAL("activated()"), SLOT("accept()"))
    
    self.pushButton_icon.clicked.connect(self.iconPushButton)
    
    self.__appName__ = QCoreApplication.applicationName()
    self.__version__ = QCoreApplication.applicationVersion()
    self.__homePage__ = QCoreApplication.organizationDomain()
    self.__author__ = QCoreApplication.organizationName()
    self.__info__ = ("<b>%s v%s</b>"
      "<p>Author: %s"
      "<p>E-mail: <a href='mailto:ncwilde43@gmail.com'>ncwilde43@gmail.com</a>"
      "<p>Homepage: <a href='%s'>%s</a>"
      "<p>License: <a href='http://www.gnu.org/licenses/gpl-3.0.txt'>GNU GPLv3</a>"
    ) % (self.__appName__,self.__version__, self.__author__, self.__homePage__,
      self.__homePage__)

    self.label_about.setText(self.__info__)
  
  def iconPushButton(self):
    """Open Homepage"""
    self.openURL(self.__homePage__)
  
  def openURL(self, url):
    """Open URL in default browser"""
    QDesktopServices.openUrl(QUrl(url))